﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZFS.Library.Helper;
using ZFS.Model;
using ZFSData;
using ZFSData.Manager;

namespace ZFS.ServerLibrary
{
    public partial class BaseService : IBaseService
    {

        #region IUserService
        
        /// <summary>
        ///  登录系统
        /// </summary>
        /// <param name="account">账户</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public byte[] Login(string account, string password)
        {
            var User = Factory.GetUserManager().Login(account, password);
            return ZipTools.CompressionObject(User);
        }

        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public byte[] GetAuthority(string account)
        {
            var UserAuth = Factory.GetUserManager().GetAuthority(account);
            byte[] bytes = ZipTools.CompressionObject(UserAuth);
            return bytes;
        }

        /// <summary>
        /// 根据账户获取账户信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public byte[] GetModelByAccount(string account)
        {
            var User = Factory.GetUserManager().GetModelByAccount(account);
            byte[] bytes = ZipTools.CompressionObject(User);
            return bytes;
        }

        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="account"></param>
        public void Logout(string account)
        {
            Factory.GetUserManager().Logout(account);
        }

        public byte[] GetModelsByUser(byte[] search)
        {
            var UserSearch = ZipTools.DecompressionObject(search) as tb_User;
            var UserList = Factory.GetUserManager().GetModels(UserSearch);
            byte[] bytes = ZipTools.CompressionObject(UserList);
            return bytes;
        }

        public byte[] GetPagingModelsByUser(int pageIndex, int pageSize, out int totalCount,
            byte[] search,
            bool Asc = false)
        {
            var UserSearch = ZipTools.DecompressionObject(search) as tb_User;
            var UserList = Factory.GetUserManager().GetPagingModels(pageIndex, pageSize, out totalCount, UserSearch, Asc);
            byte[] bytes = ZipTools.CompressionObject(UserList);
            return bytes;
        }

        public bool DeleteEntityByUser(byte[] entity)
        {
            var User = ZipTools.DecompressionObject(entity) as tb_User;
            return Factory.GetUserManager().DeleteEntity(User);
        }

        public bool UpdateEntityByUser(byte[] entity)
        {
            var User = ZipTools.DecompressionObject(entity) as tb_User;
            return Factory.GetUserManager().UpdateEntity(User);
        }

        public byte[] AddEntityByUser(byte[] entity)
        {
            var User = ZipTools.DecompressionObject(entity) as tb_User;
            var NewUser = Factory.GetUserManager().AddEntity(User);
            byte[] bytes = ZipTools.CompressionObject(NewUser);
            return bytes;
        }

        public bool ExistEntityByUser(byte[] entity)
        {
            var User = ZipTools.DecompressionObject(entity) as tb_User;
            return Factory.GetUserManager().ExistEntity(User);
        }

        #endregion

    }
}
